//
//  YJBindBankCardAlterView.m
//  YJB
//
//  Created by YJB on 2017/2/25.
//  Copyright © 2017年 YJB. All rights reserved.
//

#import "YJBindBankCardAlterView.h"
#import "masonry.h"
#import <pop/POP.h>

UIButton *alterBgView = nil;
@implementation YJBindBankCardAlterView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
        UIButton *alterContainView = [[UIButton alloc]init];
        alterContainView.backgroundColor = WHITECOLOR;
        alterContainView.layer.cornerRadius = 3;
        alterContainView.layer.masksToBounds = YES;
        alterBgView = alterContainView;
        [self addSubview:alterContainView];
        [alterContainView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(280);
            make.height.mas_equalTo(145);
            make.centerX.mas_equalTo(self.mas_centerX);
            make.centerY.mas_equalTo(self.mas_centerY);
        }];
        
        UILabel *tip = [[UILabel alloc]init];
        tip.textColor = kUIColorFromRGB(0x666666);
        tip.font = FONT(18);
        tip.text = @"持卡人说明";
        tip.textAlignment = NSTextAlignmentCenter;
        [alterContainView addSubview:tip];
        [tip mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_equalTo(0);
            make.top.mas_equalTo(5);
            make.height.mas_equalTo(45);
        }];
        
        UILabel *content = [[UILabel alloc]init];
        content.textColor = kUIColorFromRGB(0x666666);
        content.font = FONT(17);
        content.numberOfLines = 0;
        content.text = @"为了您的资金安全，只能绑定持卡人的本人银行卡";
        [alterContainView addSubview:content];
        [content mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.right.mas_equalTo(-15);
            make.top.mas_equalTo(tip.mas_bottom);
            make.height.mas_equalTo(45);
        }];
        
        UIButton *btn = [[UIButton alloc]init];
        [btn setTitle:@"我知道了" forState:UIControlStateNormal];
        btn.titleLabel.font = FONT(18);
        [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
        [btn setTitleColor:kUIColorFromRGB(0xff783d) forState:UIControlStateNormal];
        [alterContainView addSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_equalTo(0);
            make.height.mas_equalTo(50);
        }];
    }
    return self;
}

+ (void)show
{
    YJBindBankCardAlterView *alterView = [[YJBindBankCardAlterView alloc] init];
    UIWindow *win = [UIApplication sharedApplication].windows.lastObject;
    alterView.frame = win.bounds;
    [win addSubview:alterView];
    //弹出动画
    POPSpringAnimation *scaleAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerScaleXY];
    scaleAnimation.fromValue = [NSValue valueWithCGSize:CGSizeMake(0.8, 0.8)];
    scaleAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(1, 1)];
    scaleAnimation.springSpeed = 20.0f;
    scaleAnimation.springBounciness = 5.0f;
    [alterBgView.layer pop_addAnimation:scaleAnimation forKey:@"scaleAnimation"];
}

- (void)btnClick
{
    [self removeFromSuperview];
    alterBgView = nil;
}

@end
